#!/bin/bash

# Search for the process ID of ustreamer
PID="$(/bin/ps -aux | /bin/grep 'ustreamer' | egrep -v 'grep|ustreamer.log' | /usr/bin/awk '{print $2}')"

if [ -z "$PID" ];then
    echo "No active process found"
    exit
fi

echo "Stopping ustreamer... "
kill "$PID" > /dev/null 2>&1
sleep 1

# Check if the process is still running
if /bin/ps -aux | /bin/grep 'ustreamer' | egrep -v 'grep|ustreamer.log';then
    echo "Process is still running, killing it"
    kill -9 "$PID"
    exit
fi

echo "OK"

exit